<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<span>
			<input type="text" id="numId"/>
			<input type="button" value="的阶乘为" onclick="jieCheng()"/>
			<span id = "resultId"></span>
		</span>
		<script type="text/javascript">
			function jieCheng(){
				var inputObj = document.getElementById('numId');
				var result = 1;
				var resultObj = document.getElementById('resultId');
				if (inputObj.value == '' || isNaN(inputObj.value)){
					resultObj.innerHTML = '<span style="color:red">格式错误</span>'
				}
				if (parseInt(inputObj.value) < 0){
					resultObj.innerHTML = '<span style="color:red;">负数没有阶乘</span>';
				}
				for (var i = parseInt(inputObj.value); i > 0; i--){
					result *= i; 
					resultObj.innerHTML = result;
				}
				
				
			}</script>
	</body>
</html>
